<%--
  Created by IntelliJ IDEA.
  User: fire'ge
  Date: 2022/5/2
  Time: 19:43
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" isELIgnored="false" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>

<html>
<head>
    <title>菜 单 管 理</title>
    <link rel="stylesheet" href="/TakeawaySystem/css/Show.css" type="text/css">
</head>
<body>
<div>
    <table id="name-label">
        <tr>
            <td align="center" colspan="4">你好！${user.username}
                <a href="/TakeawaySystem/jsp/BusinessCenter.jsp">返回</a>  </td>
        </tr>
    </table>
    <table>
        <tr>
            <td id= "tableTopic">
                菜  单  大  全
            </td>

        </tr>
        <form id="addForm" method="post" action="business/addMenu">
        <tr>
            <td>
                菜名：<input type="text" id="addDish" name="disName">

            </td>
        </tr>
            <tr>
                <td>
                    价格：<input type="number" id="addPrice" name="price">
                </td>
            </tr>
        <tr>
            <td class="description">
                描述：<input type="text" id="addDescription" name="description">
            </td>
        </tr>
            <td>
                <input Type="hidden" name="shopId" Value="${shopId}" >
                <input Type="submit" id="addButton" name="add" Value="增 加" >

            </td>
            </form>
        <c:if test="${foods.size()-1>0}">
        <c:forEach begin="0" end="${foods.size()-1}" var="i" >
            <form method="post" id="updateForm${i}" action="business/updateMenu">
                <tr>
                    <td class="shopTopic">
                        菜名：<input type="text" id="updateDishName${i}" name="disName" value="${foods[i].dishName}">

                    </td>
                    <td >
                        <img src="/TakeawaySystem/images/shop/${foods[i].photo}" height="100" width="100">
                    </td>
                </tr>
                <tr>
                    <td>
                        价格：<input type="number" id="updatePrice${i}" name="price" value="${foods[i].price}">
                    </td>
                </tr>

                <tr>
                    <td class="description">
                        描述：<input type="text" id="updateDescription${i}" name="description" value="${foods[i].description}">
                    </td>
                </tr>
                <td>
                    <a href="business/deleteMenu?foodId=${foods[i].id}&shopId=${shopId}">删 除</a>
                    <input type="hidden" value="${foods[i].id}" name="foodId">
                    <input Type="hidden" name="shopId" Value="${shopId}" >
                    <input type="hidden" name="i" value="${i}">
                    <input Type="submit" name="update" Value="修 改" >
                </td>
            </form>

            <form action="../business/upLoadImg" method="post" enctype="multipart/form-data" >
                <tr>
                <td>
                    <input type="file" name="img" accept="image/*" >
                </td>
                <td>
                    <input type="hidden" name="foodId" value="${foods[i].id}">
                    <input type="submit" value="上传图片" >
                </td>
                </tr>
            </form>
        </c:forEach>
        </c:if>
    </table>
</div>
</body>
<script>
    let addDish = document.getElementById("addDish");
    function checkaddDish() {
        var un = addDish.value ;
        var reg = /^\d{0}$/;
        var flag = reg.test(un)
        return !flag;
    }

    let addPrice = document.getElementById("addPrice");
    function checkaddPrice() {
        var un = addPrice.value ;
        var reg = /^\d{0}$/;
        var flag = reg.test(un)
        return !flag;
    }
    let addDescription = document.getElementById("addDescription");
    function checkaddDescription() {
        var un = addDescription.value ;
        var reg = /^\d{0}$/;
        var flag = reg.test(un)
        return !flag;
    }
    let addForm = document.getElementById("addForm");
    addForm.onsubmit = checkSubmit;
    function checkSubmit() {
        var flag = checkaddDescription() && checkaddPrice()&&checkaddDish();
        return flag;
    }
        let i1 = document.getElementById("i");
    for (let i = 0; i < i1; i++) {
        function checkupdateDish() {
            var un = document.getElementById("updateDish"+i).value ;
            var reg = /^\d{0}$/;
            var flag = reg.test(un)
            return !flag;
        }

        function checkupdatePrice() {
            var un = document.getElementById("updatePrice"+i).value ;
            var reg = /^\d{0}$/;
            var flag = reg.test(un)
            return !flag;
        }
        function checkupdateDescription() {
            var un = document.getElementById("updateDescription"+i).value ;
            var reg = /^\d{0}$/;
            var flag = reg.test(un)
            return !flag;
        }
        let updateForm = document.getElementById("updateForm"+i);
        updateForm.onsubmit = checkSubmit;
        function checkSubmit() {
            var flag = checkupdateDescription() && checkupdatePrice()&&checkupdateDish();
            return flag;
        }
    }
</script>
</html>
